<template>
    <div class="resource-manage">
    <div class="card-box">
        <div class="card-title">基本信息</div>
        <el-form  class="form-wrap" size="small">
            <el-form-item label="物业编号" prop="propertyCode">
                <el-col class="in_txt">{{baseForm.propertyCode}}</el-col>
            </el-form-item>
            <el-form-item label="物业名称" prop="propertyName">
                <el-col class="in_txt">{{baseForm.propertyName}}</el-col>
            </el-form-item>
            <el-form-item label="曾用名" prop="usedName">
                <el-col class="in_txt">{{baseForm.usedName}}</el-col>
            </el-form-item>
            <el-form-item label="初始类别" prop="initialType">
                <el-col class="in_txt">{{getCardTypeValue(baseForm.initialType,initialTypes)}}</el-col>
            </el-form-item>
            <el-form-item label="规划用途" prop="planUse">
                <el-col class="in_txt">{{getCardTypeValue(baseForm.planUse,planUses)}}</el-col>
            </el-form-item>
            <el-form-item label="停车位数(个)" prop="parkingSpotNum" v-if="this.baseForm.planUse === '30'">
                <el-col class="in_txt">{{baseForm.parkingSpotNum}}</el-col>
            </el-form-item>
            <el-form-item label="总栋数(栋)" prop="totalBuildings">
                <el-col class="in_txt">{{baseForm.totalBuildings}}</el-col>
            </el-form-item>
            <el-form-item label="所属项目" prop="projectId">
                <el-col class="in_txt">{{projectNameCh}}</el-col>
            </el-form-item>
            <el-form-item label="所属楼栋" prop="buildingId">
                <el-col class="in_txt">{{buildingCh}}</el-col>
            </el-form-item>
            <el-form-item label="所属单元" prop="roomUnit">
                <el-col class="in_txt">{{baseForm.roomUnit}}</el-col>
            </el-form-item>
            <el-form-item label="所属楼层" prop="floor">
                <el-col class="in_txt">{{floorCh}}</el-col>
            </el-form-item>
            <el-form-item label="物业类型" prop="projectType">
                <el-col class="in_txt">{{dictCh(baseForm.projectType,'property_types')}}</el-col>
            </el-form-item>
            <el-form-item label="物业用途" prop="projectSubclassType">
                <el-col class="in_txt">{{dictCh(baseForm.projectSubclassType,'property_use_types')}}</el-col>
            </el-form-item>
            <el-form-item label="实际用途" prop="actualType">
                <el-col class="in_txt">{{baseForm.actualType}}</el-col>
            </el-form-item>
            <el-form-item label="占地面积(m²)" prop="floorSpace">
                <el-col class="in_txt">{{baseForm.floorSpace}}</el-col>
            </el-form-item>
            <el-form-item label="分摊公用面积(m²)" prop="apportionedArea">
                <el-col class="in_txt">{{baseForm.apportionedArea}}</el-col>
            </el-form-item>
            <el-form-item label="套内面积(m²)" prop="unitConstructionArea" >
                <el-col class="in_txt">{{baseForm.unitConstructionArea}}</el-col>
            </el-form-item>
            <el-form-item label="建筑面积(m²)" prop="buildingArea">
                <el-col class="in_txt">{{baseForm.buildingArea}}</el-col>
            </el-form-item>
            <el-form-item label="非经营面积(m²)" prop="unmanagedArea">
                <el-col class="in_txt">{{baseForm.unmanagedArea}}</el-col>
            </el-form-item>
            <el-form-item label="经营面积(m²)" prop="managedArea">
                <el-col class="in_txt">{{baseForm.managedArea}}</el-col>
            </el-form-item>

            <el-form-item label="物业权属" prop="belong">
                <el-col class="in_txt">{{getCardTypeValue(baseForm.propertyOwnership, propertyOwnerships)}}</el-col>
            </el-form-item>
            <el-form-item label="权利人" prop="occupier">
                <el-col class="in_txt">{{baseForm.occupier}}</el-col>
            </el-form-item>
            <el-form-item label="物业管理单位（公司）" prop="manager">
                <el-col class="in_txt">{{baseForm.manager}}</el-col>
            </el-form-item>
            <el-form-item label="土地使用期限" prop="serviceLife">
                <el-col class="in_txt">{{baseForm.serviceLife}}</el-col>
            </el-form-item>
            <el-form-item label="权利性质" prop="ownershipNature">
                <el-col class="in_txt">{{dictCh(baseForm.ownershipNature,'asset-ownership-nature')}}</el-col>
            </el-form-item>
            <el-form-item label="经营情况" prop="operation">
                <el-col class="in_txt">{{dictCh(baseForm.operation,'property_operations')}}</el-col>
            </el-form-item>
            <el-form-item label="可用状态" prop="status">
                <el-col class="in_txt">{{dictCh(baseForm.status,'room_use_status')}}</el-col>
            </el-form-item>
            <el-form-item label="物业状态" prop="propertyStatus">
                <el-col class="in_txt">{{dictCh(baseForm.propertyStatus,'room_status')}}</el-col>
            </el-form-item>
            <el-form-item label="物业来源" prop="propertySource">
                <el-col class="in_txt">{{dictCh(baseForm.propertySource,'property_source')}}</el-col>
            </el-form-item>
            <el-form-item label="建构日期" prop="constructionTime">
                <el-col class="in_txt">{{baseForm.constructionTime}}</el-col>
            </el-form-item>
            <el-form-item label="竣工日期" prop="endTime">
                <el-col class="in_txt">{{baseForm.endTime}}</el-col>
            </el-form-item>
            <el-form-item label="建构价格(元)" prop="suggestPrice">
                <el-col class="in_txt">{{baseForm.suggestPrice}}</el-col>
            </el-form-item>
            <el-form-item label="管理权属">
                <el-col class="in_txt">{{dictCh(baseForm.manageUnit,'administrative_office')}}</el-col>
            </el-form-item>
            <!--<el-form-item label="街道" >
                <el-col class="in_txt">{{dictCh(baseForm.roomStreet,'streets')}}</el-col>
            </el-form-item>
            <el-form-item label="社区" >
                <el-col class="in_txt">{{dictCh(baseForm.communityName,'community_names')}}</el-col>
            </el-form-item>-->
            <el-form-item label="物业地址" class="full">
                <el-col class="in_txt">{{getCardTypeValue(baseForm.cityCode,cityAssembly)}}{{getCardTypeValue(baseForm.countyCode,districtCollection)}}{{getCardTypeValue(baseForm.roomStreet,streets)}}{{getCardTypeValue(baseForm.communityName,communityNames)}}{{baseForm.address}}</el-col>
            </el-form-item>
            <el-form-item label="地图坐标">
                <el-col class="in_txt">{{baseForm.mapCoordinates}}</el-col>
            </el-form-item>
           <!-- <el-form-item label="地址" class="col-two">
                <el-col class="in_txt">{{baseForm.areaName}}</el-col>
            </el-form-item>
            <el-form-item label="详细地址" prop="address">
                <el-col class="in_txt">{{baseForm.address}}</el-col>
            </el-form-item>-->
            <el-form-item label="VR地址">
                <el-col class="in_txt">{{baseForm.vrUrl}}</el-col>
            </el-form-item>
					<el-form-item label="数据渠道" >
						<span class="in_txt">{{getCardTypeValue(baseForm.channel,propertyChannels)}}</span>
					</el-form-item>
            <el-form-item label="备注" prop="remarks" class="full">
                <el-col class="in_txt">{{baseForm.remarks}}</el-col>
            </el-form-item>
        </el-form>
    </div>
    </div>
</template>

<script>
    import {getAllProject,getAddress} from "@/views/property-info-sys/project-manage/api/project_manage"
    import { getChild, buildBuildingUnit,validateRoomCode } from "@/views/property-info-sys/property-manage/api/room"
    import { getDict } from '~/utils'
    import {mapGetters} from "vuex";

    export default {
        name: "base-info",
        data() {
            return {
                baseForm: {
                    propertyCode: '',
                    propertyName: '',
                    projectId: '',
                    buildingId: '',
                    roomUnit: '',
                    initialType: '',
                    planUse: '',
                    totalBuildings: '',
                    parkingSpotNum: '',
                    floor: '',
                    propertyType:'',
                    useType:'',
                    actualType: '',
                    buildingArea: '',
                    unitConstructionArea: '',
                    operation: '',
                    status: '',
                    propertySource: '',
                    constructionTime: '',
                    suggestPrice: '',
                    address: '',
                    remarks: '',
                    areaCode: '',
                    areaName: '',
                    provinceCode: '',
                    usedName: '',
                    roomStreet: '',
                    cityCode: '',
                    countyCode: '',
                    communityName: '',
                    endTime: '',
                },
                projectForm: {
                    useLandArea: '',
                    floorSpace: '',
                    useArea: '',
                    unmanagedArea: '',
                    managedArea: '',
                    noApportionedArea: '',
                    belong: '',
                    obligee: '',
                    occupier: '',
                    manager: '',
                    serviceLife: '',
                    ownershipNature: '',
                    propertyStatus: '',
                    cityCode: '',
                    countyCode: '',
                    projectStreet: '',
                    addressInfo: '',
                    communityName: '',
                    areaCode: '',
                    areaName: '',
                },
                projects: [],
                buildings: [],
                roomUnits: [],
                floors: [],
                streets: [],
                communityNames: [],
                initialTypes: [],
                planUses: [],
                belongs: [],
                propertyOwnerships: [],
							propertyChannels:[]
            }
        },
        created() {
            this.propertyOwnerships = getDict('property_ownerships')
            this.communityNames = getDict('community_names')
            this.streets = getDict('streets')
            this.planUses = getDict('plan_uses')
            this.belongs = getDict('belongs')
            this.initialTypes = getDict('project_init_type')
					  this.propertyChannels = this.getDict("property_channel")
            getAllProject().then(rep => {
                let projectData = rep.data.data
                if(projectData){
                    this.projects = projectData.map( p => {
                        return {label: p.projectName, value: p.projectId}
                    })
                }
            })
            getAddress(this.projectId).then(res => {
                if (res.data.code === 0 && res.data.data !== null) {
                    this.projectForm = res.data.data
                    this.projectForm.cityCode = this.projectForm.areaCode.split('-')[0]
                    this.projectForm.countyCode = this.projectForm.areaCode.split('-')[1]
                }
            })
        },
        computed: {
            projectNameCh: function () {
                let find = this.projects.find(p => p.value == this.baseForm.projectId )
                if(find){
                    return find.label
                }
                return ""
            },
            buildingCh: function () {
                let find = this.buildings.find(p => p.value == this.baseForm.buildingId )
                if(find){
                    return find.label
                }
                return ""
            },
            floorCh: function () {
                let find = this.floors.find(p => p.value == this.baseForm.floor )
                if(find){
                    return find.label
                }
                return ""
            },
            ...mapGetters({
                cityAssembly: 'getCityAssembly',
                districtCollection: 'getDistrictCollection',
            })
        },
        methods: {
            dictCh(val, dictName){
                if(val && dictName){
                    let dict = getDict(dictName)
                    if(dict){
                        let find = dict.find(d => d.value == val)
                        if(find){
                            return find.label
                        }
                    }
                }
                return ""
            },
            updateInit(data){
                console.log('data---',data)
                this.baseForm = data
                this.baseForm.cityCode = this.baseForm.areaCode.split('-')[0]
                this.baseForm.countyCode = this.baseForm.areaCode.split('-')[1]
                this.baseForm.roomStreet = this.getCardTypeValue(this.baseForm.roomStreet,this.streets)
                this.queryBuilding()
                this.queryFloor()
            },
            queryBuilding(){
                getChild(this.baseForm.projectId, '2').then( rep => {
                    let building = rep.data.data
                    if(building.treeNode){
                        this.buildings = building.treeNode.map(b => {
                            return {label: b.label, value: b.nodeId}
                        })
                    }
                })
            },

            queryFloor(){
                //获取单元
                buildBuildingUnit(this.baseForm.buildingId).then(rep => {
                    this.roomUnits = rep.data.data
                })
                //获取所有楼层
                getChild(this.baseForm.buildingId, '3').then( rep => {
                    let floors = rep.data.data
                    if(floors.treeNode){
                        this.floors = floors.treeNode.map(b => {
                            return {label: b.label+'层', value: b.nodeId}
                        })
                    }
                })
            },
            // hxf-1010-回显时对应value显示label
            getCardTypeValue(num, sum){
                let arr = sum.filter(e=>e.value === num)
                if (arr.length > 0) {
                    return arr[0].label
                } else {
                    return num
                }
            }
        },
        props: ['projectId']
    }
</script>

<style scoped lang='scss'>


    @include formWrap();
    .in_txt {
        color: #999999;
    }
</style>
